<template>
    <el-main>
        <addEditPbArticleView ref="addEditPbArticleView" @call-parent-method="getPbArticleList" />
        <div class="app-table">
            <div class="app-body">
                <el-form :inline="true" class="demo-form-inline" v-model="form">
                    <el-form-item label="标题">
                        <el-input placeholder="请输入标题" v-model="form.title"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="简介">
                        <el-input placeholder="请输入简介" v-model="form.brief"></el-input>
                    </el-form-item>
                    <el-form-item label="封面图片">
                        <el-input placeholder="请输入封面图片" v-model="form.imgUrl"></el-input>
                    </el-form-item>
                    <el-form-item label="封面视频">
                        <el-input placeholder="请输入封面视频" v-model="form.videoUrl"></el-input>
                    </el-form-item> -->
                    <el-form-item label="发布人">
                        <el-input placeholder="请输入发布人" v-model="form.publishName"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button class="serach_btn" type="primary" @click="onSubmit"
                            @keyup.enter="searchEnter">搜索</el-button>
                        <el-button class="add_btn" type="success" @click="add">添加</el-button>
                        <el-button class="export_btn" type="warning" @click="exportExcel">导出报表</el-button>
                        <!-- <el-button type="danger" @click="importExcel">批量导入
                            <el-icon class="el-icon--right">
                                <Upload />
                            </el-icon>
                        </el-button> -->
                    </el-form-item>
                </el-form>
                <el-table size="small" :data="list" style="width: 100%" :row-class-name="tableRowClassName">
                    <el-table-column prop="id" label="id" />
                    <el-table-column prop="title" label="标题" />
                    <!-- <el-table-column prop="brief" label="简介" />
                    <el-table-column prop="imgUrl" label="封面图片" />
                    <el-table-column prop="videoUrl" label="封面视频" /> -->
                    <!-- <el-table-column prop="content" label="详细内容" /> -->
                    <!-- <el-table-column prop="publishDate" label="内容日期" />
                    <el-table-column prop="createTime" label="创建时间" /> -->
                    <el-table-column prop="publishName" label="发布人" />
                    <!-- <el-table-column prop="sortNum" label="权重" />
                    <el-table-column prop="isEffect" label="是否禁用" />
                    <el-table-column prop="isTop" label="是否置顶" />
                    <el-table-column prop="typeId" label="分类" /> -->
                    <el-table-column label="操作" width="170px">
                        <template #default="scope">
                            <el-button class="edit_btn" size="mini" type="success" @click="editPbArticle(scope.row)">编辑
                            </el-button>
                            <el-button class="del_btn" size="mini" type="danger" @click="deletePbArticle(scope.row.id)">删除
                            </el-button>
                        </template>
                    </el-table-column>
                    <template v-slot:empty>
                        <el-empty description="暂无数据"></el-empty>
                    </template>
                </el-table>
                <el-config-provider :locale="locale">
                    <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                        layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                        @current-change="changeCurrentPage">
                    </el-pagination>
                </el-config-provider>
            </div>
            <bottomView />
        </div>
    </el-main>
</template>
<script>


import addEditPbArticleView from "@/components/reportWork/addEditPbArticle.vue";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import bottomView from "@/components/bottom.vue";

export default {
    name: "PbArticleListView",
    data() {
        return {
            type: 0,
            title: "",
            page: 0,
            pageSize: 10,
            total: 0,
            limit: 10,
            list: [],
            form: {
                title: "",
                brief: "",
                imgUrl: "",
                videoUrl: "",
                publishName: "",
            },
        };
    },
    components: {
        addEditPbArticleView, bottomView
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
        this.getPbArticleList();
    },
    watch: {
        $route() {
            this.getPbArticleList();
        },
    },
    methods: {
        searchEnter: function (e) {
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getPbArticleList();
            }
        },
        add() {
            console.log(this.$refs.addEditPbArticleView);
            this.$refs.addEditPbArticleView.title = "添加文章表"
            // this.$refs.addEditPbArticleView.personnelType = this.type
            this.$refs.addEditPbArticleView.initTinymce();
            this.$refs.addEditPbArticleView.dialogFormVisible = true;
        },
        editPbArticle(obj) {
            this.$refs.addEditPbArticleView.title = "修改信息"
            this.$refs.addEditPbArticleView.getPbArticleById(obj.id);
            this.$refs.addEditPbArticleView.dialogFormVisible = true;
        },

        deletePbArticle(id) {
            this.$confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService("/javaApi/pbArticle/deleteById", "id=" + id, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                this.$message({
                                    type: "success",
                                    message: "删除成功!",
                                });
                                this.getPbArticleList();
                            } else {
                                this.$message({
                                    type: "error",
                                    message: "删除失败，请重试！",
                                });
                            }
                        }
                    );
                })
                .catch(() => {
                });
        },
        reloadData() {
            this.page = 1;
            this.getPbArticleList()
        },
        importExcel() {
            this.$refs.addFileView.dialogFormVisible = true;
            this.$refs.addFileView.title = "批量导入文章表";
            this.$refs.addFileView.uploadApiUrl = "/javaApi/pbArticle/importExcel";
        },
        exportExcel() {
            httpService(
                "/javaApi/pbArticle/exportExcel",
                {
                    "title": this.form.title,
                    // "brief": this.form.brief,
                    // "imgUrl": this.form.imgUrl,
                    // "videoUrl": this.form.videoUrl,
                    "publishName": this.form.publishName,
                },
                "get"
            ).then((data) => {
                if (data.code == 200) {
                    // window.open(data.message, '_blank')
                    window.open(`https://wx.zhengzhong.cn${data.message}`, '_blank')
                }
            });
        },
        onSubmit() {
            this.getPbArticleList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getPbArticleList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getPbArticleList();
        },
        tableRowClassName({ row, rowIndex }) {
            return "";
        },
        getPbArticleList() {
            httpService(
                "/javaApi/pbArticle/list/" + this.page + "/" + this.pageSize,
                {
                    "title": this.form.title,
                    "brief": this.form.brief,
                    "imgUrl": this.form.imgUrl,
                    "videoUrl": this.form.videoUrl,
                    "publishName": this.form.publishName,
                },
                "get"
            ).then((data) => {
                this.list = data.list;
                this.total = data.total;
                this.pageCount = data.pages;
            });
        },
    },
};
</script>
<style scoped>
.app-table {
    background: #eff3f5;
    padding: 10px;
}

.app-body {
    background: white;
    padding: 20px 20px 10px 20px;
    margin-bottom: 10px;
    min-height: calc(100vh - 216px);
}

.el-main {
    --el-main-padding: 0px;
}

.serach_btn {
    background-color: #007EFF;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.add_btn {
    background-color: #00c78c;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.export_btn {
    background-color: #FF7200;
    border-radius: 8px;
    color: #fff;
    border: none;
}

.edit_btn {
    background-color: #fff;
    color: #007EFF;
    border: none;
}

.del_btn {
    background-color: #fff;
    color: #FF0000;
    border: none;
}
</style>

